package com.ruoyi.web.controller.order;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.UserNotice;
import com.ruoyi.order.service.IUserNoticeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户通知表Controller
 * 
 * @author ruoyi
 * @date 2022-02-04
 */
@Controller
@RequestMapping("/order/userNotice")
public class UserNoticeController extends BaseController
{
    private String prefix = "order/userNotice";

    @Autowired
    private IUserNoticeService userNoticeService;

    @RequiresPermissions("order:userNotice:view")
    @GetMapping()
    public String userNotice()
    {
        return prefix + "/userNotice";
    }

    /**
     * 查询用户通知表列表
     */
    @RequiresPermissions("order:userNotice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserNotice userNotice)
    {
        startPage();
        List<UserNotice> list = userNoticeService.selectUserNoticeList(userNotice);
        return getDataTable(list);
    }

    /**
     * 导出用户通知表列表
     */
    @RequiresPermissions("order:userNotice:export")
    @Log(title = "用户通知表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserNotice userNotice)
    {
        List<UserNotice> list = userNoticeService.selectUserNoticeList(userNotice);
        ExcelUtil<UserNotice> util = new ExcelUtil<UserNotice>(UserNotice.class);
        return util.exportExcel(list, "用户通知表数据");
    }

    /**
     * 新增用户通知表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户通知表
     */
    @RequiresPermissions("order:userNotice:add")
    @Log(title = "用户通知表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UserNotice userNotice)
    {

        return toAjax(userNoticeService.insertUserNotice(userNotice));
    }

    /**
     * 修改用户通知表
     */
    @RequiresPermissions("order:userNotice:edit")
    @GetMapping("/edit/{noticeID}")
    public String edit(@PathVariable("noticeID") Integer noticeID, ModelMap mmap)
    {
        UserNotice userNotice = userNoticeService.selectUserNoticeByNoticeID(noticeID);
        mmap.put("userNotice", userNotice);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户通知表
     */
    @RequiresPermissions("order:userNotice:edit")
    @Log(title = "用户通知表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UserNotice userNotice)
    {
        return toAjax(userNoticeService.updateUserNotice(userNotice));
    }

    /**
     * 删除用户通知表
     */
    @RequiresPermissions("order:userNotice:remove")
    @Log(title = "用户通知表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(userNoticeService.deleteUserNoticeByNoticeIDs(ids));
    }
}
